
import string

class Player:

  # This is the constructor method.
  # It takes a data string and fills a player's stats
  # NOTE: The data string must be in the standard
  # USAToday stats format
  #
  # **Arguments** 
  #
  # *data* a string containing one line of data
  #
  # **returns** none
  def __init__(self,data):
    s = string.split(data)
  
    # This is a pain in the ass, but if two players on
    # a team have the same last name, you will have 19 field
    # instead of 18, so check separately for the two cases
    if len(s) == 18:
      self.name = s[0]
      self.ba   = float(s[1])
      self.slg  = float(s[2])
      self.oba  =float(s[3])
      self.g=float(s[4])
      self.ab=float(s[5])
      self.r=float(s[6])
      self.h=float(s[7])
      self.tb=float(s[8])
      self.twob=float(s[9])
      self.threeb=float(s[10])
      self.hr=float(s[11])
      self.rbi=float(s[12])
      self.bb=float(s[13])
      self.so=float(s[13])
      self.sb=float(s[15])
      self.cs=float(s[16])
      self.e=float(s[17])

    # This is a player who has a first initial
    # so add first two fields together to get name
    if len(s) == 19:
      self.name = s[0]+s[1]
      self.ba   = float(s[2])
      self.slg  = float(s[2])
      self.oba  =float(s[4])
      self.g=float(s[5])
      self.ab=float(s[6])
      self.r=float(s[7])
      self.h=float(s[8])
      self.tb=float(s[9])
      self.twob=float(s[10])
      self.threeb=float(s[11])
      self.hr=float(s[12])
      self.rbi=float(s[13])
      self.bb=float(s[14])
      self.so=float(s[15])
      self.sb=float(s[16])
      self.cs=float(s[17])
      self.e=float(s[18])
